<template>
	<div class="context">
		<h2 class="h2">审核店铺详细信息</h2>
		<div class="info">
			<h4 class="h4">头像：<img :src="shop.headPortrait" width="200" height="200" /></h4>
			<h4 class="h4">店铺名：{{shop.shopName}}</h4>
			<h4 class="h4">店铺电话：{{shop.phone}}</h4>
			<h4 class="h4">店铺地址：{{shop.address}}</h4>
			<h4 class="h4">店铺类型：{{shop.shopType}}</h4>
			<h4 class="h4">店铺描述：{{shop.shopDescription}}</h4>
			<!-- <h4 class="h4">用户编号：{{shop.userId}}</h4> -->
		</div>
		<div class="butten">
			<el-button type="success" @click="auditShopOK()">审核通过</el-button>
			<el-button type="danger" @click="auditDeny()">拒绝通过</el-button>
		</div>
	</div>
</template>

<script>
	import qs from 'qs'
	import {
		ElNotification
	} from 'element-plus'
	import {
		ElMessageBox,
		ElMessage
	} from 'element-plus'
	export default {
		data() {
			return {
				shop: [],
				shopId: 0
			}
		},
		methods: {
			//根据店铺编号审核店铺信息
			getAuditShopInfo() {
				this.shopId = this.$route.params.shopId
				this.$axios.get("/shop/getAuditShopInfo", {
					params: {
						shopId: this.$route.params.shopId
					}
				}).then(res => {
					this.shop = res.shop
				})
			},
			//返回按钮 回到审核列表页面
			auditDeny() {
				ElMessageBox.prompt('请输入拒绝原因:', '原因', {
						cancelButtonText: '取消',
						confirmButtonText: '发送',
						/* inputPattern:
						  /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
						inputErrorMessage: 'Invalid Email', */
					})
					.then(({
						value
					}) => {

						this.$axios.get("/user/mail/sendAuditInfo", {
								params: {
									denyInfo: value,
									userId: this.shop.userId,
									shopName: this.shop.shopName
								}
							})
							.then(res => {
								if (res.data == "success") {
									console.log("shopId:"+this.shop.shopId)
									this.$axios.post("/shop/deleteShop",qs.stringify({
										"shopId": this.shop.id
									}))
									.then(res => {
										if(res.judge){
											console.log("删除成功！");
										}else{
											console.log("删除失败！");
										}
									})
									ElMessage({
										type: 'success',
										message: `发送成功,原因:${value}`,
									})
									this.$router.push("/auditShop")
								}
							})

					})
					.catch(() => {
						ElMessage({
							type: 'info',
							message: '取消发送!!!',
						})
					})

			},
			//审核通过按钮
			auditShopOK() {
				console.log("shopId=" + this.shopId);
				// let shop ={ 'shopId':shopId };
				this.$axios.post("/shop/auditShopOK", qs.stringify({
						'shopId': this.shopId
					}))
					.then(res => {
						if (res.judge) {
							ElNotification({
								title: '成功提示',
								message: '审核通过！！！',
								type: 'success',
							})
							this.getAuditShop()
						} else {
							ElNotification({
								title: '错误提示',
								message: '审核通过失败！！！',
								type: 'error',
							})
						}
					})
			}
		},
		mounted() {
			this.getAuditShopInfo()
		}
	}
</script>

<style>
	.context {
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		margin-left: 20px;
		margin-top: -20px;
	}

	.info {
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		margin-left: 400px;
	}

	.h4 {
		line-height: 20px;
	}

	.butten {
		margin-left: 1000px;
	}
</style>
